import java.util.Scanner;

/**
 * InputThread reads user input from STDIN
 */
class ClientInputThread extends Thread {
	private ClientImpl client;
	private boolean running;
	private boolean waitingForInput;
	private Scanner scanner;

	public ClientInputThread(ClientImpl client) {
		this.client = client;
	}

	public void run() {
		scanner = new Scanner(System.in);
		running = true;
		while (running) {
				String inputLine;

				System.out.print("input > ");
				waitingForInput = true;
				inputLine = scanner.nextLine();
				waitingForInput = false;

				if (inputLine.length() > 0) {
					String[] requestParameters = client.getRequestParameters(inputLine);
					client.encodeRequest(requestParameters);
				}
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
					running = false;
				}
		}
	}

	public void shutdown() {
		running = false;
		interrupt();
		scanner.close();
	}
	
	public boolean isWaitingForInput() {
		return waitingForInput;
	}
}